/**
 * jims
 */
package com.jims.master.modules.base.netHosptial.service;


import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.base.netHosptial.dao.NetSettingDao;
import com.jims.master.modules.base.netHosptial.entity.NetSetting;
import com.jims.master.modules.base.user.entity.MasterBaseinfo;
import com.jims.master.modules.base.user.entity.MasterDoctorinfo;
import com.jims.master.modules.base.user.service.MasterDoctorinfoService;
import com.jims.master.modules.sys.entity.OrgDict;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service
 * @author xueyx
 * @version 2017-05-23
 */
@Service
@Transactional(readOnly = true)
public class NetSettingService extends CrudService<NetSettingDao, NetSetting> {
	@Autowired
	private MasterDoctorinfoService masterDoctorinfoService;
	@Override
    public NetSetting get(String id) {
		return super.get(id);
	}

	@Override
    public List<NetSetting> findList(NetSetting netSetting) {
		return super.findList(netSetting);
	}

	@Override
    public Page<NetSetting> findPage(Page<NetSetting> page, NetSetting netSetting) {
		return super.findPage(page, netSetting);
	}

	@Override
    @Transactional(readOnly = false)
	public int save(NetSetting netSetting) {
		return super.save(netSetting);
	}

	@Override
    @Transactional(readOnly = false)
	public int delete(NetSetting netSetting) {
		return super.delete(netSetting);
	}

	public NetSetting getInfoByEntity(NetSetting netSetting){
		return dao.getInfoByEntity(netSetting);
	}

	/**
	 * 查询医生已签约机构
	 * @param  id
	 * @author WangYQ
	 * @return
	 */
	public List<OrgDict> getSignedOrgDict(String id){
		MasterDoctorinfo masterDoctorinfo=masterDoctorinfoService.get(id);
		MasterBaseinfo masterBaseinfo=masterDoctorinfo.getBaseinfo();
		if(masterBaseinfo!=null){
			if(masterBaseinfo.getId()!=null&&!masterBaseinfo.getId().equals("")){
				return dao.getSignedOrgDict(masterBaseinfo.getId());
			}
		}
		return null;
	}
	/**
	 * 查询申请过的所有医院
	 * @param  doctorId
	 * @author WangYQ
	 * @return
	 */
	public List<OrgDict> findAppliedHospital(String doctorId){
		MasterDoctorinfo masterDoctorinfo=masterDoctorinfoService.get(doctorId);
		MasterBaseinfo masterBaseinfo=masterDoctorinfo.getBaseinfo();
		if(masterBaseinfo!=null){
			if(masterBaseinfo.getId()!=null&&!masterBaseinfo.getId().equals("")){
				return dao.findAppliedHospital(masterBaseinfo.getId());
			}
		}
		return null;
	};
	/**
	 * 判断是否申请该医院
	 * @param  netSetting
	 * @author WangYQ
	 * @return
	 */
	public int judgeAppliedHospital(NetSetting netSetting){
		return this.dao.judgeAppliedHospital(netSetting);
	}
}